package com.biz.primus.ms.order.dao.po;

import com.biz.primus.model.order.enums.AuditState;
import com.biz.primus.model.order.enums.ReturnState;
import com.biz.primus.model.order.enums.ReturnType;
import com.biz.primus.ms.base.jpa.converter.ListStringConverter;
import com.biz.primus.ms.base.jpa.po.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.List;

/**
 * 退货订单
 *
 * @author Tiger Feng
 * @date 2017年11月18日
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "ord_return_order", indexes = {
        @Index(name = "idx_ord_return_order_order_code", columnList = "orderCode"),
        @Index(name = "idx_ord_return_order_depot_ode", columnList = "depotCode")
})
public class ReturnOrder extends BaseEntity {
    private static final long serialVersionUID = 8147058998509947710L;

    // 关联订单(orphanRemoval = true, cascade = CascadeType.ALL)
    @OneToOne
    @JoinColumn(name = "order_id", nullable = false)
    private Order order;

    @OneToMany(mappedBy = "returnOrder", orphanRemoval = true, cascade = CascadeType.ALL)
    private List<ReturnOrderItem> items;
    // 退货单编号
    @Column(length = 64, unique = true, nullable = false)
    private String returnCode;
    // 操作人ID
    @Column(nullable = false)
    private Long userId;

    // 订单编号
    @Column(length = 64, unique = true, nullable = false)
    private String orderCode;

    // 门店编号(退货门店)
    @Column(length = 64)
    private String depotCode;
    // 门店收货人
    @Column(length = 32)
    private String depotConsignee;
    // 门店联系电话
    @Column(length = 32)
    private String depotTelephone;
    // 门店完整地址
    @Column
    private String depotAddress;
    // 门店邮政编码
    @Column(length = 16)
    private String depotZipCode;

    // 退货(售后)类型
    @Column(nullable = false)
    @Convert(converter = ReturnType.Converter.class)
    private ReturnType returnType;
    // 退货(售后)用户上传图片列表，最多3张
    @Column
    private String returnUserDescription;
    // 退货(售后)用户上传图片列表，最多3张
    @Column(columnDefinition = "TEXT")
    @Convert(converter = ListStringConverter.class)
    private List<String> returnUserImages;
    // 退货状态
    @Column(nullable = false)
    @Convert(converter = ReturnState.Converter.class)
    private ReturnState returnState = ReturnState.AUDITING;

    // 快递费
    @Column
    private Integer expressAmout;
    // 退款金额
    @Column
    private Integer amount;
    // 已退款金额
    @Column
    private Integer liquidated = 0;

    // 推送OMS时间
    @Column
    private Timestamp send2OMSTimestamp;
    // 酒库审核状态(未审核、通过、未通过)
    @Column(nullable = false)
    @Convert(converter = AuditState.Converter.class)
    private AuditState auditState = AuditState.UNAUDITED;
    // 审核时间
    private Timestamp auditTimestamp;

    // 退货物流公司
    @Column(length = 32)
    private String expressName;
    // 退货物流单号
    @Column(length = 128)
    private String expressNumber;
    // 退货时用户说明：
    @Column
    private String expressUserDescription;
    // 退货时客服说明：
    @Column
    private String expressServiceDescription;
    // 用户上传凭证图片,最多3张
    @Column(columnDefinition = "TEXT")
    @Convert(converter = ListStringConverter.class)
    private List<String> expressUserImages;
    // 客服上传的凭证图片，最多3张
    @Column(columnDefinition = "TEXT")
    @Convert(converter = ListStringConverter.class)
    private List<String> expressServiceImages;


}
